package edu.nf.relaxenjoy.web.controller.app;

import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.service.EsService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author zhu
 * @date 2024-12-17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/search/searchRecord")
public class SearchRecordEsController extends BaseController {

    private final EsService esService;

    /**
     * 增加搜索记录
     *
     * @param keyword
     * @throws IOException
     */
    @RequestMapping("addSearchRecordData")
    public ResultVO addSearchRecordData(String keyword) throws IOException {
        esService.addSearchRecordData(keyword);
        return success();
    }

    /**
     * 搜索记录
     *
     * @param keyword
     * @return
     * @throws IOException
     */
    @RequestMapping("esSearchRecord")
    public ResultVO esSearchRecord(String keyword) throws IOException {
        List<Map<String, Object>> res = esService.esSearchRecord(keyword);
        return success(res);
    }
}
